function  [x_opt,f_opt,stepNum]=FibonacciOpt(f,a,b,Theta_error)

%% compute Fn and the step numbers
Fn=(b-a)/Theta_error;
x=[];
x(1)=1;
x(2)=1;
i=1;
while x(i)<Fn
    x(i+2)=x(i)+x(i+1);
    i=i+1;
end

N=i;
%% the Opt Algorithm
a1=x(N-2)/x(N)*(b-a)+a;
a2=x(N-1)/x(N)*(b-a)+a;

for i=1:N-3
f1=feval(f,a1);
f2=feval(f,a2);
if f1>f2
       a=a1;
       f1=f2;
       a1=a2;
       a2=a+x(N-i-1)/x(N-i)*(b-a);     
    else
       b=a2;
       a2=a1;
       f2=f1;
       a1=a+x(N-i-2)/x(N-i)*(b-a);       
end 
stepNum=i;
end
   x_opt=(a+b)/2;
   f_opt=feval(f,x_opt);
   stepNum=stepNum+1;



